const menu = {
    state: {
        currentMenu: null, //tag
        result: "", //存储tabList数组的剩余元素数量
        tabList: [],
    },

    mutations: {
        /* tag */
        //点击菜单栏
        selectMenu(state, val) {
            if (val.url) {
                state.currentMenu = val; //把当前菜单的val = index + name + url
                let result = state.tabList.findIndex(item => item.url == val.url); //寻找tabList是否有相同的路径（返回下标），如果没有找到对应的下标，则将val添加到tabList
                if (result == -1) {
                    state.tabList.push(val)
                }
            } else {
                state.currentMenu = null //lwj
            }
        },
        // 关闭tab标签 
        closeTabs(state, val) {
            let result = state.tabList.findIndex(item => item.url == val.url); //查找点击的下标，然后删除该下标的对应数据，更新tabList和result
            state.tabList.splice(result, 1)
            state.result = result
        },
    },

    actions: {

    },
};

export default menu;